<?php
require(dirname(__FILE__)."/includes/init.php");
if(isset($_SESSION['user_name'])){
if(isset($_REQUEST['Submit'])){
	$sqlArr = $_REQUEST['sql'];
	$sqlA = explode(";",$sqlArr);
	foreach($sqlA as $value){
		$GLOBALS['db']->dbquery($value);
	}
	echo "success";
}
$result = '';
if(isset($_REQUEST['SubmitCheck'])){
	$sqlCheck = $_REQUEST['sqlCheck'];
	$result = $GLOBALS['db']->dbfetchAll($sqlCheck);
}

if(isset($_REQUEST['SubmitGet'])){
	$sqlCheck = $_REQUEST['sqlCheck'];
	$results = $GLOBALS['db']->dbfetchAll($sqlCheck);
	if(!empty($results)){
		$num = count($results[0]);
		$nums = $num/2;
	}else{
		exit;
	}
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>直接SQL</title>
</head>

<body>
<form action="sql.php" method="post" name="sqlCheck">
<table width="1292" border="0" bgcolor="#0066FF" style="font-size:12px">
  <tr bgcolor="#FFFFFF">
    <td colspan="3"><div align="center">查询SQL</div></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>SQLS:</td>
    <td><input name="sqlCheck" type="text" id="sqlCheck" size="85"></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="51">结果:</td>
    <td width="539"><textarea name="result" cols="100" rows="30" id="result"><?php 
	if(!empty($results)){
		echo "<table border=\"0\" bgcolor=\"#993333\">";
		foreach($results as $key=>$value){
			echo "<tr bgcolor=\"#FFFFFF\">";
			for($i=0;$i<$nums;$i++){
				echo "<td>".$value[$i]."</td>";
			}
			echo "</tr>";
		}
		echo "</table>";	
	}
	?></textarea></td>
    <td width="539">&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td><input type="submit" name="SubmitGet" value="查询" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>

<form action="sql.php" method="post" name="sql">
<table width="1294" border="0" bgcolor="#0066FF" style="font-size:12px">
  <tr bgcolor="#FFFFFF">
    <td colspan="3"><div align="center">直接SQL</div></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="51">SQL:</td>
    <td width="539"><textarea name="sql" cols="100" rows="30" id="sql"></textarea></td>
    <td width="539" valign="top">清除三天以前生成的发送完成的模板<Br/>
      <span style="border:#FF0000 solid 2px; height:20px; width:85px;">delete from tempTemplate where flag = 1 and timeStamps &lt; <?php 
	  $timeStr = formateTime();
	  echo $timeStr- 172800; ?></span> </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="执行" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>

<form action="sql.php" method="post" name="sqlCheck">
<table width="1292" border="0" bgcolor="#0066FF" style="font-size:12px">
  <tr bgcolor="#FFFFFF">
    <td colspan="3"><div align="center">查询SQL</div></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>SQLS:</td>
    <td><input name="sqlCheck" type="text" id="sqlCheck" size="85"></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="51">结果:</td>
    <td width="539"><textarea name="result" cols="100" rows="30" id="result"><?php echo "<pre>";print_r($result);?></textarea></td>
    <td width="539">&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td><input type="submit" name="SubmitCheck" value="查询" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
<?php
}else{
 echo "hello";
}
?>